/*
 * test.hpp
 *
 *  Created on: 15/05/2009
 *      Author: desadoc
 */

#ifndef TEST_HPP_
#define TEST_HPP_

#include <iostream>

static bool _TEST_CASE_OK;

template <typename T>
std::string to_str(T v)
{
	std::string _l;

	while(v>0)
	{
		_l = (char) (48 + v%10) + _l;
		v /= 10;
	}

	return _l;
}

std::string add_spaces(const std::string& str, int length)
{
	std::string _l;

	while(_l.size()<(length-str.size()))
	{
		_l += " ";
	}

	_l += str;

	return _l;
}

template <typename T>
static bool assert(const char* msg, int line, T v)
{
	std::string ln = to_str(line);
	ln = add_spaces(ln, 5);

	if(!v)
	{
		std::cout << " -\tline " << ln.c_str() << ": FAILED: " << msg << "\n";
		_TEST_CASE_OK = false;
		return false;
	} else {
		std::cout << " -\tline " << ln.c_str() << ": PASSED\n";
		return true;
	}
}

#define BEGIN_TEST_CASE() do{ _TEST_CASE_OK = true; std::cout << " # Running test case: " << args[1] << "\n"; }while(false)
#define ASSERT(msg, param...) assert(msg, __LINE__, param)
#define END_TEST_CASE() do{ std::cout << " # Ended test case: " << args[1] << "\n"; }while(false)

#endif /* TEST_HPP_ */
